module.exports = class extends think.Controller {
  async __before() {
    // 根据token值获取用户id
    this.ctx.state.token = this.ctx.header['access-min-token'] || '';
    const tokenSerivce = think.service('token', 'api');
    this.ctx.state.userId = await tokenSerivce.getUserId(this.ctx.state.token);
    // this.ctx.state.companyId = await tokenSerivce.getCompanyId(this.ctx.state.token);
    // this.ctx.state.dictId = await tokenSerivce.getUserDict(this.ctx.state.token);

    // 只允许登录操作
    // if (this.ctx.controller !== 'index' && this.ctx.controller !== 'auth' && this.ctx.controller !== 'payNotify') {
    //   if (this.ctx.state.userId <= 0) {
    //     return this.fail(401, '请先登录');
    //   }
    // }
  }

  getLoginUserId() {
    return this.ctx.state.userId || 9159;
  }

  getLoginCompanyId() {
    return this.ctx.state.companyId;
  }

  getLoginUserDict() {
    return this.ctx.state.dictId;
  }
};
